package org.example.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("mvc")
public class FileUploadController {

    @PostMapping("/upload")
    public ResponseEntity<String> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        String fileName = UUID.randomUUID().toString();

        // 目标文件路径
        File destFile = new File("C:\\dev\\pressTest\\mvc\\" + fileName + ".tar");
        file.transferTo(destFile);

        return new ResponseEntity<>("MVC File '" + file.getOriginalFilename() + "' uploaded.", HttpStatus.OK);
    }
}
